package com.company;

import java.io.*;

public class Task3 {


    public static void main(String[] args) {
       //todo 3.编写一段程序，循环从键盘输入一行字符，把这行字符首尾颠倒后按行输出到一个文件中，遇到quit后退出。
        String url = "D:/study/io";
        BufferedInputStream bis = new BufferedInputStream(System.in);
        byte[] buf = new byte[1024];
        try {
            while (true) {
                int len = bis.read(buf);
                String line = new String(buf, 0, len);
                if (line.contains("quit")) {
                    System.out.println(line + "退出");
                    break;
                }
                String path = url + "/test.txt";
                StringBuffer sb = new StringBuffer();
                sb.append(line);
                sb.reverse();
                String str = sb.toString();
                if (str == null || str == "") {
                    continue;
                }
                System.out.println("输出" + str);
                Writer output = new FileWriter(path, true);
                output.write(str);
                output.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bis != null) {
                try{
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
